package artid.com.arttogo.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.bumptech.glide.Glide;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.SpecialInformationParser;
import artid.com.arttogo.db.Cache;
import artid.com.arttogo.network.AppUtil;
import artid.com.arttogo.network.VolleyBasic;
import artid.com.arttogo.network.VolleyCallback;
import artid.com.arttogo.network.VolleyData;
import artid.com.arttogo.network.VolleyMap;
import artid.com.arttogo.utils.MyBitmapImageViewTarget;
import artid.com.arttogo.utils.NetUtils;
import artid.com.arttogo.view.DynamicHeightImageView;

/**
 * 
 *    
 * 项目名称：ArtworkArt   
 * 类名称：AuctionSpecialInformation_Activity   
 * 类描述：拍卖会-专场详情-专场信息   
 * 创建人：耿卫斌   
 * 创建时间：2017-3-2 下午1:48:45   
 *
 */
public class AuctionSpecialInformation_Activity extends BaseActivity implements OnClickListener {
	private ImageView title_rightBtn;
	private TextView previewTime,previewAddress,auctionTime,auctionAddress,historicalTurnover,turnoverRate,
	auctionTitle,auctionTime2,auctionNum,auctionCompany,auctionAddress2;
	private LinearLayout auctionHouse;
	private DynamicHeightImageView auctionImg;
	private String SpecialID;//专场ID
	private String imgwide;// 请求的图片宽度
	private SpecialInformationParser bean;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_auctionspecialinformation);
		initView();
	}
	private void initView(){
		mContext=AuctionSpecialInformation_Activity.this;
		SpecialID=getIntent().getStringExtra("SpecialID");
		imgwide = (Integer.parseInt(NetUtils.getDisplayMetrics((Activity) mContext).get(NetUtils.DM_WIDTH)) / 1) + "";
		mBack = (ImageView) findViewById(R.id.back_btn);
		mBack.setOnClickListener(this);
		mTittle = (TextView) findViewById(R.id.tittle_text);
		mTittle.setText("专场信息");
		title_rightBtn=(ImageView) findViewById(R.id.share_collection_detail);
		title_rightBtn.setVisibility(View.GONE);
		title_rightBtn.setOnClickListener(this);
		previewTime=(TextView) findViewById(R.id.AuctionSpecialInformation_PreviewTime);
		previewAddress=(TextView) findViewById(R.id.AuctionSpecialInformation_PreviewAddress);
		auctionTime=(TextView) findViewById(R.id.AuctionSpecialInformation_auctionTime);
		auctionAddress=(TextView) findViewById(R.id.AuctionSpecialInformation_auctionAddress);
		historicalTurnover=(TextView) findViewById(R.id.AuctionSpecialInformation_HistoricalTurnover);
		turnoverRate=(TextView) findViewById(R.id.AuctionSpecialInformation_TurnoverRate);
		auctionHouse=(LinearLayout) findViewById(R.id.AuctionSpecialInformation_auctionHouseLL);
		auctionHouse.setOnClickListener(this);
		auctionImg=(DynamicHeightImageView) findViewById(R.id.AuctionSpecialInformation_auctionImg);
		auctionTitle=(TextView) findViewById(R.id.AuctionSpecialInformation_auctionTitle);
		auctionTime2=(TextView) findViewById(R.id.AuctionSpecialInformation_auctionTime2);
		auctionNum=(TextView) findViewById(R.id.AuctionSpecialInformation_auctionNum);
		auctionCompany=(TextView) findViewById(R.id.AuctionSpecialInformation_auctionCompany);
		auctionAddress2=(TextView) findViewById(R.id.AuctionSpecialInformation_auctionAddress2);
		getData();
	}

	@Override
	public void onClick(View v) {
		Intent intent;
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back_btn:
			finish();
			break;
		case R.id.share_collection_detail:
			//标题右按钮
			if(bean!=null){
				String content="预展:"+bean.getSpecialinfo().getPreview_start_time()+"-"+bean.getSpecialinfo().getPreview_end_time()
						+"/"+bean.getSpecialinfo().getPreview_address()+"/"+"拍卖:"+bean.getSpecialinfo().getAuction_start_time()
						+"-"+bean.getSpecialinfo().getAuction_end_time()+"/"+bean.getSpecialinfo().getAuction_address();
			AppUtil.shareAuction(mContext, "3", bean.getSpecialinfo().getTitle(), content, "这里填写图片地址",
						"http://www.baidu.com", bean.getSpecialinfo().getId(), false);
			}
			break;
		case R.id.AuctionSpecialInformation_auctionHouseLL:
			//所属拍卖会
			intent=new Intent(mContext,AuctionInfo_Activity.class);
			intent.putExtra("auctionID", bean.getAuctioninfo().getId());
			intent.putExtra("SpecialListData", 0);
			startActivity(intent);
			break;

		default:
			break;
		}
	}
	
	/**
	 * 获取专场详情信息数据
	 */
	private void getData(){
		VolleyBasic.getInstance(this).post(Cache.specialMsg,
				VolleyMap.getInstance().specialMsg(SpecialID,imgwide),
				SpecialInformationParser.class, new VolleyCallback() {

			@Override
			public void onSuccess(VolleyData vd) {
				// TODO Auto-generated method stub
				bean=(SpecialInformationParser) vd.getData();
				previewTime.setText(bean.getSpecialinfo().getPreview_start_time()+"-"+bean.getSpecialinfo().getPreview_end_time());
				previewAddress.setText(bean.getSpecialinfo().getPreview_address());
				auctionTime.setText(bean.getSpecialinfo().getAuction_start_time()+"-"+bean.getSpecialinfo().getAuction_end_time());
				auctionAddress.setText(bean.getSpecialinfo().getAuction_address());
				historicalTurnover.setText(bean.getSpecialinfo().getUnit()+" "+bean.getSpecialinfo().getTurnover());
				turnoverRate.setText(bean.getSpecialinfo().getTurnoverrate()+"%");
                auctionImg.isRightAngle=true;
                auctionImg.setHeight(bean.getAuctioninfo().getHeight());
				Glide.with(mContext).load(bean.getAuctioninfo().getImgurl()
						+ "_"+ (Integer.parseInt(NetUtils.getDisplayMetrics((Activity)mContext).get(NetUtils.DM_WIDTH)) /3) + "x10.png"
						).asBitmap().centerCrop()
						.placeholder(R.drawable.ic_menu_rotate).error(R.drawable.ic_menu_rotate)
						.into(new MyBitmapImageViewTarget(auctionImg));
				auctionTitle.setText(bean.getAuctioninfo().getTitle());
				auctionTime2.setText(bean.getAuctioninfo().getStart_time()+"-"+bean.getAuctioninfo().getEnd_time());
				auctionNum.setText(bean.getAuctioninfo().getSpecial_num()+"个专场 / "+
												bean.getAuctioninfo().getLotrecord_num()+"件备案 / "+
												bean.getAuctioninfo().getLot_num()+"件拍品");
				auctionCompany.setText(bean.getAuctioninfo().getSeller_name());
				auctionAddress2.setText(bean.getAuctioninfo().getAddress());
			}

			@Override
			public void onError(VolleyError volleyError) {
				// TODO Auto-generated method stub
			}
		});
	}
}
